package com.shenma2009.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenma2009.domain.ResultResponse;
import com.shenma2009.pojo.TbUploadFile;
import com.shenma2009.service.TbUploadFileService;
import com.shenma2009.mapper.TbUploadFileMapper;
import com.shenma2009.utils.AliyunOssUtil;
import com.shenma2009.vo.UploadImageResultWang;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
* @author 33509
* @description 针对表【tb_upload_file(上传文件表)】的数据库操作Service实现
* @createDate 2023-04-22 11:33:17
*/
@Service
public class TbUploadFileServiceImpl extends ServiceImpl<TbUploadFileMapper, TbUploadFile>
    implements TbUploadFileService{

    @Override
    public ResultResponse upload(MultipartFile file) {

        AliyunOssUtil oss = AliyunOssUtil.OSS();
        String url = oss.upload(file);

        //
        TbUploadFile tbUploadFile = new TbUploadFile();
        tbUploadFile.setFileUrl(url);
        tbUploadFile.setFileName(oss.getFileName());
        tbUploadFile.setFileSize(oss.getFileSize());

        this.save(tbUploadFile);


        return ResultResponse.SUCCESS(url);
    }

    @Override
    public UploadImageResultWang uploadWang(String token, MultipartFile file) {

        AliyunOssUtil oss = AliyunOssUtil.OSS();
        String url = oss.upload(file);

        //
        TbUploadFile tbUploadFile = new TbUploadFile();
        tbUploadFile.setFileUrl(url);
        tbUploadFile.setFileName(oss.getFileName());
        tbUploadFile.setFileSize(oss.getFileSize());

        this.save(tbUploadFile);

        UploadImageResultWang resultWang = new UploadImageResultWang(0, "上传成", url, oss.getFileName(), oss.getFileUrl());

        return resultWang;
    }
}




